<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';	
include '../../content-accountant/invoicetax.php';
$stonggiacungcap=0;
$stongthue=0;
$stongtien=0;
$arr=array();
$status=$_REQUEST['status'];
if($status==0){
	$l_ngaygiaodich=$l_ngaygiaodich0;
	$l_ngayphathanh=$l_ngayphathanh0;	
	$l_thoigiangiaodich=$l_thoigiangiaodich0;
}
if($status==1){
	$l_ngaygiaodich=$l_ngaygiaodich1;
	$l_ngayphathanh=$l_ngayphathanh1;	
	$l_thoigiangiaodich=$l_thoigiangiaodich1;
}
$typedate=$_REQUEST['typedate'];
if($typedate=='ngayph'){
	$time='order_time';
	$type=$l_phathanh;
}
if($typedate=='ngaygd'){
	$time='order_time_transaction';
	$type=$l_giaodich;
}
if(isset($_REQUEST['loaitimkiem'])){
	if($_REQUEST['loaitimkiem']=="ngay"){
		$sql="SELECT or_order_tax.*   
		from or_order_tax  
		where or_order_tax.order_cusname like '%".$_REQUEST['cusname']."%'";
		if(isset($_REQUEST['df']) && isset($_REQUEST['dt'])){
			if($_REQUEST['df']!="" && $_REQUEST['dt']!=""){
				$sql .=" and ( or_order_tax.$time >= '".$_REQUEST['df']."' and or_order_tax.$time <= '".$_REQUEST['dt']."' ) ";
			}
		}
		$sql.="and is_status=".$status." order by or_order_tax.$time";
		$sqlinvoice=mysql_query($sql);
		if(mysql_num_rows($sqlinvoice)>0){
			while($rin=mysql_fetch_array($sqlinvoice)){
				$ob=new invoicetax();
				
				if($rin[$time]=='0000-00-00' || $rin[$time]=='')
					$ktdate=0;
				else
					$ktdate=getdate(strtotime($rin[$time]));
				
				$ob->Instance($rin['orderid'],$rin['order_time'],$ktdate['mon'],$ktdate['day'],$ktdate['year'],$rin['order_cus'],$rin['order_content'],$rin['order_quantity'],$rin['order_supply_rice'],$rin['order_tax'],$rin['order_total'],$rin['order_time_transaction'],$rin['is_status'],$rin['user_create'],$rin['date_create'] );
				$ob->setCusname($rin['order_cusname']);
				if(array_key_exists ($rin[$time], $arr)==true){
					array_push ($arr[$rin[$time]],$ob);
				}else{
					$arr[$rin[$time]]=array();
					$arr[$rin[$time]][]=$ob;
				}
			}
			$_SESSION['manginvoicetax']=$arr;
		}
	}
}

?>
			<div class="title2">
			    	<!-- <span style="float:left"><?php echo $l_company_name?> : ELisoft</span>
			        <span style="float:right">
			        <?php 
			        if($_REQUEST['cusname']!=""){
			        	?>
			        	<?php echo $l_tenkhachhanggiaodich;?> : <?php echo $_REQUEST['cusname'];?>
			        	<?php 
			        }
			        ?>
			        
			        </span>-->
			    </div>
			    <div style="clear:both"></div>
	        	<div style="position:relative">
			        <div>
			        	<table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable" >
				            <tr>
				                <th><?=$l_no?></th>
				                <th><?=$l_ngaythangnam?></th>
				                <th><?=$l_company_name?></th>
				                <th width="30%"><?=$l_product_item?></th>
				                <th><?=$l_quantity?></th>
				                <th><?=$l_Supply_price?></th>
				                <th><?=$l_vat?></th>
				                <th><?=$l_amount?></th>
				                <th><?=$l_thoigiangiaodich?></th>
				            </tr>
				           
				           <?php
				           $soluong= count($arr);
				           if($soluong>0){
				           		$vitri=0;
				           		foreach($arr as $thoigian=>$mgiatri){
				           			$tonggiacungcap=0;
				           			$tongthue=0;
				           			$tongtien=0;
				           			$dem=count($mgiatri);
				           			if($dem>0){
				           				for($i=0;$i<$dem;$i++){
				           					$inobject= unserialize (serialize ($mgiatri[$i]));
				           					
				           ?>
								            <tr>
								                <td style="padding: 5px;"><?=($vitri+1)?></td>
								                <td><?=$inobject->ordertime?></td>
								                <td style="text-align:left"><?=$inobject->cusname?></td>
								                <td style="text-align:left"><?=$inobject->order_content?></td>
								                <td><?=number_format($inobject->order_quantity)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_suplly_rice)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_tax)?></td>
								                <td style="text-align:right;"><?=number_format($inobject->order_total)?></td>
								                <td><?=$inobject->order_time_transaction?></td>
								            </tr>
						            <?php 
						            		$tonggiacungcap +=$inobject->order_suplly_rice;
						            		$tongthue +=$inobject->order_tax;
						            		$tongtien +=$inobject->order_total;
						            		$vitri++;
				           				}
				           			}
				           			?>
						            <tr class="coltr2" style="font-weight:bold;font-size:14px;">
						                <td colspan="4"  style="padding: 10px;">
											<?php 
												if($_REQUEST['loaitimkiem']=="thang"){
													?>
													<?php echo $l_month;?> : <?php ?>  -  <?php echo $l_co;?>  <?php echo number_format($dem);?> <?php echo $type;?>
													<?php 
												}else if($_REQUEST['loaitimkiem']=="qui"){
													?>
													<?php echo $l_quy;?> : <?php ?>  -  <?php echo $l_co;?>  <?php echo number_format($dem);?> <?php echo $type;?>
													<?php 
												}else{
													?>
													<?php echo $l_days;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($dem);?></font> 
													<?php 
												}
											?>
										</td>
						                <td></td>
						                <td style="text-align:right;"><?php echo number_format($tonggiacungcap);?></td>
						                <td style="text-align:right;"><?php echo number_format($tongthue);?></td>
						                <td style="text-align:right;"><?php echo number_format($tongtien);?></td>
						                <td></td>
						            </tr>
				           <?php 
				           			$stonggiacungcap +=$tonggiacungcap;
				           			$stongthue +=$tongthue;
				           			$stongtien +=$tongtien;
				           			
				           		}
				           }else{
				           ?>
				            <tr><td colspan="9" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty;?></td></tr>
				           <?php 
				           }
				           ?>
				            
				            <tr style="font-weight:bold;font-size:15px;color:green;">
				                <td colspan="4" style="padding: 10px;"><?php echo $l_tongdon?></td>
				                <td></td>
				                <td style="text-align:right;"><?php echo number_format($stonggiacungcap);?></td>
				                <td style="text-align:right;"><?php echo number_format($stongthue);?></td>
				                <td style="text-align:right;"><?php echo number_format($stongtien);?></td>
				                <td style="text-align:right;"></td>
				            </tr>
				        </table>
			        </div>
        		</div>
        		<?php 
        		if($soluong>0){
        			if($_REQUEST['loaitimkiem']=="ngay"){
        			?>
        			<div class="fbox2" style="text-align:center; width:100%;">
        				<a href="printer/ajax_export_acc.php?type=ngay&typedate=<?php echo $typedate;?>&cusname=<?php echo $_REQUEST['cusname'];?>&df=<?php echo $_REQUEST['df']; ?>&dt=<?php echo $_REQUEST['dt'];?>&status=<?=$status?>"><input type="button" value="<?=$l_export_excel?>" class="btnupbg btnupload" style="background: #4f81bd;"/></a>
        				<a href="printer/or_printer_search_invoice_tax.php?type=ngay&typedate=<?php echo $typedate;?>&cusname=<?php echo $_REQUEST['cusname'];?>&df=<?php echo $_REQUEST['df']; ?>&dt=<?php echo $_REQUEST['dt'];?>&status=<?=$status?>" target="_blank"><input type="button" value="<?=$l_print?>" class="btnupbg btnupload" style="background: #4f81bd;"/></a>
        			</div>
        			<?php	
        			}
        		}
        		?>
